package com.learning.jquizenglish.widget;

import com.learning.jquizenglish.R;
import com.learning.jquizenglish.activity.MainActivity;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.LinearLayout;

public class SquareLayout extends LinearLayout {

	
	private int layoutScale;
	
	public SquareLayout(Context context) {
		super(context);
	}

	public SquareLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.SquareImageView);
		layoutScale = arr.getInteger(R.styleable.SquareImageView_siv_scale, 2);
		arr.recycle();
	}

//	public SquareLayout(Context context, AttributeSet attrs, int defStyle) {
//		super(context, attrs, defStyle);
//	}

	public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//		int size = Math.min(getMeasuredWidth(), getMeasuredHeight());
		int size = MainActivity.SCREEN_WIDTH/layoutScale;
		setMeasuredDimension(size,size);
	}
}
